<?php

class Contact extends CI_Controller {

	function __construct()
	{
		parent:: __construct();
		$this->load->model('Contact_model');
		if(!$this->session->userdata('user_id') && !$this->session->userdata('user_display_name') ):
			redirect('backend');
		endif;
	}

	function index()
	{
	
		$offset = $this->uri->segment(4);
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/backend/contact/index';
		$config['total_rows'] = count($this->Contact_model->getContact(FALSE,FALSE,FALSE,FALSE));
		$config['per_page'] = 10;
		$config['uri_segment'] = '4';
		$this->pagination->initialize($config);
		$data['urut'] = $this->uri->segment(4);
		$data['title'] = 'Kontak Kami';
		$data['template'] = 'contact/index';
		$data['res_con'] = $this->Contact_model->getContact(FALSE,FALSE,$config['per_page'],$offset);
		$this->load->view('backend/index',$data);
		
	}

	function detail()
	{
		$id = $this->uri->segment(4);
		$data['title'] = 'Kontak Kami';
		$data['template'] = 'contact/detail';
		$data['contact'] = $this->Contact_model->getContact('detail',$id,FALSE,FALSE);
		$data['status'] = array('status'=>'read');
		$this->Contact_model->updateContact($data['contact']->kontak_id,$data['status']);
		$this->load->view('backend/index',$data);
	}
	
	function ajax_bulk_action()
	{
		foreach($_POST["kontak_id"] as $id):
			$this->db->where('kontak_id',$id);
			$this->db->delete('tb_kontak');
		endforeach;
	}
	
	function delete()
	{
		$id = $this->uri->segment(4);
		$uri = $this->uri->segment(5);
		$this->Contact_model->deleteContact($id);
		$count = count($this->Contact_model->getContact(FALSE,FALSE,FALSE));
		getPage('contact','delete',$uri,$count);
	}
	

}